package com.iwunu.gateway.service.impl;

import com.iwunu.gateway.entity.InspectRecords;
import com.iwunu.gateway.repository.InspectRecordsRepository;
import com.iwunu.gateway.service.InspectRecodesService;
import com.iwunu.gateway.vo.InspectRecordsVo;
import java.util.Date;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author kinfeng
 * @date 2021/7/30 5:48 PM
 * @description
 */
@Service
public class InspectRecordsServiceImpl implements InspectRecodesService {
	@Autowired
	private InspectRecordsRepository inspectRecordsRepository;

	@Override
	public InspectRecords save(InspectRecordsVo vo) {
		InspectRecords ir = new InspectRecords();
		BeanUtils.copyProperties(vo, ir);
		ir.setCreateTime(new Date());
		return inspectRecordsRepository.saveAndFlush(ir);
	}

	@Override
	public InspectRecords selectRecodes(String deviceId) {
		List<InspectRecords> recodes = inspectRecordsRepository.selectInspectRecords(deviceId);
		if (recodes != null && recodes.size() > 0) {
			return recodes.get(0);
		}
		return null;
	}

	@Override
	public InspectRecords update(InspectRecords ir) {
//		inspectRecordsRepository.deleteById(ir.getId());
		ir.setCreateTime(new Date());
		return inspectRecordsRepository.saveAndFlush(ir);
	}

}
